// *************************************************************************************************
//
// QPropertyEditor v 0.3
//   
// --------------------------------------
// Copyright (C) 2007 Volker Wiendl
// Acknowledgements to Roman alias banal from qt-apps.org for the Enum enhancement
//
//
// The QPropertyEditor Library is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation version 3 of the License 
//
// The Horde3D Scene Editor is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
// *************************************************************************************************

#include "QPropertyEditorWidget.h"
#include "QPropertyModel.h"
#include "QVariantDelegate.h"
#include "Property.h"
#include <QtGui/QHeaderView>

QPropertyEditorWidget::QPropertyEditorWidget(QWidget* parent /*= 0*/) : QTreeView(parent)
{
	m_model = new QPropertyModel(this);		
	setModel(m_model);
	setItemDelegate(new QVariantDelegate(this));
	
	setAlternatingRowColors(true);
	setAnimated ( true );
	setRootIsDecorated ( false );

setStyleSheet(QString(
	"	QTreeView {"
"selection-color: yellow;"
                         "selection-background-color: blue;"
	"paint-alternating-row-colors-for-empty-area:true;"

  "show-decoration-selected: 0;"
"background:transparent;"
"background-color:rgb(232,232,232);"
"  alternate-background-color: rgb(214,222,212);"



 "}"

 " QTreeView::item {"
"background:transparent;"
"background-color:green;"
"  alternate-background-color: yellow;"

 "     border: 1px solid #d9d9d9;"
 "    border-top-color: transparent;"
 "    border-bottom-color: transparent;"
 "}"

 "QTreeView::item:hover {"
 "    background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1);"
  "   border: 1px solid #bfcde4;"
" }"

" QTreeView::item:selected {"
 "    border: 1px solid #567dbc;"
" }"

" QTreeView::item:selected:active{"
   "  background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6ea1f1, stop: 1 #567dbc);"
" }"

" QTreeView::item:root:active{"
   "  background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6ea1f1, stop: 1 #567dbc);"
" }"

		


));


	//this->header()->setStyleSheet(tr("background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6ea1f1, stop: 1 #567dbc);"))	;


}


QPropertyEditorWidget::~QPropertyEditorWidget()
{
}

void QPropertyEditorWidget::addObject(QObject* propertyObject)
{
	m_model->addItem(propertyObject);
	expandToDepth(0);
}

void QPropertyEditorWidget::setObject(QObject* propertyObject)
{
	m_model->clear();
	if (propertyObject)
		addObject(propertyObject);
}

void QPropertyEditorWidget::updateObject(QObject* propertyObject)
{
	if (propertyObject)
		m_model->updateItem(propertyObject);	
}

void QPropertyEditorWidget::registerCustomPropertyCB(UserTypeCB callback)
{
	m_model->registerCustomPropertyCB(callback);
}

void QPropertyEditorWidget::unregisterCustomPropertyCB(UserTypeCB callback)
{
	m_model->unregisterCustomPropertyCB(callback);
}

